/*
 * WorkerThread.cpp
 *
 *  Created on: Sep 10, 2011
 *      Author: Gherman Alin
 */

#include "WorkerThread.h"

const int QUEUE_SIZE = 256;

namespace Worker {

WorkerThread::WorkerThread() :
		Threads::Thread(), running(true), queue(QUEUE_SIZE) {
}

WorkerThread::~WorkerThread() {
	join();
}

bool WorkerThread::add(Command* command) {
	queue.put(command);
	return true;
}

void WorkerThread::run() {
	while (running) {
		Command* c = queue.take();
		running = execute(c);
		delete c;
	}
}

void WorkerThread::stop() {
	running = false;
}

bool WorkerThread::isRunning() {
	return running;
}

}

